package com.stylefeng.guns.modular.advertisement.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.modular.advertisement.entity.AppAdDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.AppAds;
import com.stylefeng.guns.modular.advertisement.service.IAppAdsService;

/**
 * 广告管理控制器
 *
 * @author fengshuonan
 * @Date 2020-06-11 19:20:38
 */
@Controller
@RequestMapping("/appAds")
public class AppAdsController extends BaseController {

    private String PREFIX = "/advertisement/appAds/";

    @Autowired
    private IAppAdsService appAdsService;

    /**
     * 跳转到广告管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "appAds_add.html";
    }

    /**
     * 跳转到添加广告管理
     */
    @RequestMapping("/appAds_add")
    public String appAdsAdd() {
        return PREFIX + "appAds_add.html";
    }

    /**
     * 跳转到修改广告管理
     */
    @RequestMapping("/appAds_update/{appAdsId}")
    public String appAdsUpdate(@PathVariable Integer appAdsId, Model model) {
        AppAds appAds = appAdsService.selectById(appAdsId);
        model.addAttribute("item",appAds);
        LogObjectHolder.me().set(appAds);
        return PREFIX + "appAds_edit.html";
    }

    /**
     * 获取广告管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return appAdsService.selectList(null);
    }

    /**
     * 新增广告管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AppAdDto adv) {
        System.out.println(adv);
        appAdsService.createNewAdvertisement(adv);
        return SUCCESS_TIP;
    }

    /**
     * 删除广告管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer appAdsId) {
        appAdsService.deleteById(appAdsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改广告管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AppAds appAds) {
        appAdsService.updateById(appAds);
        return SUCCESS_TIP;
    }

    /**
     * 广告管理详情
     */
    @RequestMapping(value = "/detail/{appAdsId}")
    @ResponseBody
    public Object detail(@PathVariable("appAdsId") Integer appAdsId) {
        return appAdsService.selectById(appAdsId);
    }
}
